/*
 * Copyright 2013 Glassy Cinema.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hu.glassy.core.model;

import hu.glassy.model.common.SortableAbstractEntity;
import hu.glassy.web.util.Country;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Represents the Movie
 *
 * @author Alexander Molnár <molnar.alexander@sonrisa.hu>
 */
@Entity
@Table(name = "movie")
public class Movie extends SortableAbstractEntity
{

  // Field lengths
  public static final int TITLE_LENGTH = 160;
  public static final int SHORT_DESCRIPTION_LENGTH = 1024;
  public static final int LONG_DESCRIPTION_LENGTH = 6 * 1024;

  // Required fields
  public static final boolean TITLE_REQUIRED = true;
  public static final boolean SHORT_DESCRIPTION_REQUIRED = true;
  public static final boolean LONG_DESCRIPTION_REQUIRED = true;
  public static final boolean TOTAL_LENGTH_REQUIRED = true;
  public static final boolean RELEASE_DATE_REQUIRED = true;
  public static final boolean RELEASE_COUNTRY_REQUIRED = true;

  @Column(name = "title", length = TITLE_LENGTH, nullable = !TITLE_REQUIRED, unique = false)
  private String title;

  @Column(name = "short_description", length = SHORT_DESCRIPTION_LENGTH, nullable = !SHORT_DESCRIPTION_REQUIRED, unique = false)
  private String shortDescription;

  @Column(name = "long_description", length = LONG_DESCRIPTION_LENGTH, nullable = !LONG_DESCRIPTION_REQUIRED, unique = false)
  private String longDescription;

  @Column(name = "total_length", nullable = !TOTAL_LENGTH_REQUIRED, unique = false)
  private Integer totalLength;

  // TODO: The release date is not specified. For example there
  // can be an estimated release date, or just a year...
  @Temporal(TemporalType.DATE)
  @Column(name = "release_date", nullable = !RELEASE_DATE_REQUIRED, unique = false)
  private Date releaseDate;

  @Column(name = "release_country", length = 2, nullable = !RELEASE_COUNTRY_REQUIRED, unique = false)
  private String releaseCountry = Country.HU.getCountryCode();

  @ManyToOne
  @JoinColumn(name = "posterimage_id", referencedColumnName = "id", nullable = true, unique = false)
  private PosterImage posterImage;

  /**
   * @return the title
   */
  public String getTitle()
  {
    return title;
  }

  /**
   * @param title the title to set
   */
  public void setTitle(String title)
  {
    this.title = title;
  }

  /**
   * @return the shortDescription
   */
  public String getShortDescription()
  {
    return shortDescription;
  }

  /**
   * @param shortDescription the shortDescription to set
   */
  public void setShortDescription(String shortDescription)
  {
    this.shortDescription = shortDescription;
  }

  /**
   * @return the longDescription
   */
  public String getLongDescription()
  {
    return longDescription;
  }

  /**
   * @param longDescription the longDescription to set
   */
  public void setLongDescription(String longDescription)
  {
    this.longDescription = longDescription;
  }

  /**
   * @return the totalLength
   */
  public Integer getTotalLength()
  {
    return totalLength;
  }

  /**
   * @param totalLength the totalLength to set
   */
  public void setTotalLength(Integer totalLength)
  {
    this.totalLength = totalLength;
  }

  /**
   * @return the releaseDate
   */
  public Date getReleaseDate()
  {
    return releaseDate;
  }

  /**
   * @param releaseDate the releaseDate to set
   */
  public void setReleaseDate(Date releaseDate)
  {
    this.releaseDate = releaseDate;
  }

  /**
   * @return the releaseCountry
   */
  public Country getReleaseCountry()
  {
    return Country.valueOf(releaseCountry);
  }

  /**
   * @param releaseCountry the releaseCountry to set
   */
  public void setReleaseCountry(Country releaseCountry)
  {
    this.releaseCountry = releaseCountry.getCountryCode();
  }

  /**
   * @return the posterImage
   */
  public PosterImage getPosterImage()
  {
    return posterImage;
  }

  /**
   * @param posterImage the posterImage to set
   */
  public void setPosterImage(PosterImage posterImage)
  {
    this.posterImage = posterImage;
  }

}
